from pyasn1.codec.der.encoder import encode
from pyasn1.codec.cer.decoder import decode
from pyasn1.debug import hexdump
from schema import *


def X501factory(attribute_list: {str: str}) -> RDNSequence:
    rnd = RDNSequence()
    for key, value in attribute_list.items():
        attrib = AttributeValueAssertion()
        attrib['attributeType'] = ObjectIdentifier(key)
        attrib['attributeValue'] = PrintableString(value)

        relative = RelativeDistinguishedName()
        relative.setComponentByPosition(0, attrib)
        rnd.append(relative)

    return rnd


rnd = X501factory({
    '2.5.4.6': 'US',
    '2.5.4.10': 'Exampla Organization',
    '2.5.4.3': 'Test User 1'
})
print(hexdump(encode(rnd)))

received_record, _ = decode(encode(rnd))

print(received_record)
